package com.demo.common.dynamic.datasource.utils;

import cn.hutool.extra.spring.SpringUtil;
import com.demo.common.dynamic.datasource.service.DataSourceConfigService;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;


/**
 * 数据源配置自动初始化
 *
 * @author molong
 * @since 2021/10/28
 */
public class DsAutoInitEvent implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        DataSourceConfigService dataSourceConfigService = SpringUtil.getBean(DataSourceConfigService.class);
        //自动初始化
        dataSourceConfigService.initDataSource();
    }
}
